package com.tangula.android.base

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import com.tangula.android.kashine.db.DemoEntity
import com.tangula.android.orm.BaseDataBaseHelper

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
 * Instrumented test, which will execute on an Android device.
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
    @Test
    fun useAppContext() {
        // Context of the app under test.
        val appContext = InstrumentationRegistry.getTargetContext()
        assertEquals("com.tangula.android.base", appContext.packageName)
    }


    @Test
    fun dbcreate() {
        // Context of the app under test.
        //val appContext = InstrumentationRegistry.getTargetContext()
        BaseDataBaseHelper.createTable(DemoEntity::class.java,true)

        class H: BaseDataBaseHelper<DemoEntity>()

        val h = H()
        val entity = h.save(DemoEntity().also {
            it.id=null
            it.name="a"
        })

        val query_res = h.byId(entity!!.id)
        assertNotNull(query_res)
        assertEquals(query_res!!.id, entity.id)
        assertEquals(query_res.name, entity.name)

    }


}
